package com.anycc.cloud.auth.userdetails;

import com.anycc.cloud.auth.service.feign.AccountService;
import com.anycc.cloud.core.dto.AccountDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * custom account user info by jdbc
 */
@Service
public class CustomUserDetailService implements UserDetailsService {
    @Autowired
    //编译器报错，无视。 因为这个Bean是在程序启动的时候注入的，编译器感知不到，所以报错。
    private AccountService accountService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        AccountDto account = accountService.findByUsername(username);
        return new UserDetailsImpl(account);
    }
}
